<#include "../common/layout/__sublayout.html">

    <!--设置面包屑-->
    <#assign pageBreadCrumbs>
        <li class="active"><a href="#">应用管理</a></li>
        <li class="active">上传应用</li>
    </#assign>
    <#assign pageCss>
        <!-- page specific plugin styles -->
        <link rel="stylesheet" href="${ctx}/static/admin/assets/css/jquery-ui.custom.css" />
        <link rel="stylesheet" href="${ctx}/static/admin/assets/css/chosen.css" />
        <link rel="stylesheet" href="${ctx}/static/admin/assets/css/datepicker.css" />
    </#assign>

    <#assign pageJavascript>
        <script src="${ctx}/static/admin/assets/js/jquery.dataTables.js"></script>
        <script src="${ctx}/static/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
        <script src="${ctx}/static/admin/assets/js/ajaxfileupload.js"></script>
        <script src="${ctx}/static/admin/assets/js/bootstrap-wysiwyg.js"></script>
        <script src="${ctx}/static/admin/assets/js/jquery.validate.js"></script>
        <script src="${ctx}/static/admin/assets/js/jquery.validate.messages_zh.js"></script>
        <script type="text/javascript">
            var $path_assets = "${ctx}/static/admin/assets/";//this will be used in loading jQuery UI if needed!
        </script>
        <script type="text/javascript">
            jQuery(function($){

                //初始化数据展示
                $("#clientType").val(${vo.clientType!});
                $("#language").val(${vo.language!});
                $("#isLastVersion").val(${vo.isLastVersion!});
                $("#firmware").val(${vo.firmware!});
                $("#channelId").val(${vo.channelId!});

                function showErrorAlert (reason, detail) {
                    var msg='';
                    if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
                    else {
                        //console.log("error uploading file", reason, detail);
                    }
                    $('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+
                    '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
                }

                $('#descriptiondiv').ace_wysiwyg({
                    toolbar:
                            [
                                'font',
                                null,
                                'fontSize',
                                null,
                                {name:'bold', className:'btn-info'},
                                {name:'italic', className:'btn-info'},
                                {name:'strikethrough', className:'btn-info'},
                                {name:'underline', className:'btn-info'},
                                null,
                                {name:'insertunorderedlist', className:'btn-success'},
                                {name:'insertorderedlist', className:'btn-success'},
                                {name:'outdent', className:'btn-purple'},
                                {name:'indent', className:'btn-purple'},
                                null,
                                {name:'justifyleft', className:'btn-primary'},
                                {name:'justifycenter', className:'btn-primary'},
                                {name:'justifyright', className:'btn-primary'},
                                {name:'justifyfull', className:'btn-inverse'},
                                null,
                                {name:'createLink', className:'btn-pink'},
                                {name:'unlink', className:'btn-pink'},
                                null,
                                {name:'insertImage', className:'btn-success'},
                                null,
                                'foreColor',
                                null,
                                {name:'undo', className:'btn-grey'},
                                {name:'redo', className:'btn-grey'}
                            ],
                    'wysiwyg': {
                        fileUploadError: showErrorAlert
                    }
                }).prev().addClass('wysiwyg-style2');

                $("#clientVersionForm").validate({
                    errorElement: 'div',
                    errorClass: 'help-block',
                    focusInvalid: true,
                    highlight: function (e) {
                        $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
                    },
                    success: function (e) {
                        $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                        $(e).remove();
                    },
                    errorPlacement: function (error, element) {
                        if (element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
                            var controls = element.closest('div[class*="col-"]');
                            if (controls.find(':checkbox,:radio').length > 1) controls.append(error);
                            else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                        }
                        else if (element.is('.select2')) {
                            error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                        }
                        else if (element.is('.chosen-select')) {
                            error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                        }
                        else error.insertAfter(element.parent());
                    },

                    submitHandler: function (form) {
                        $.ajax({
                            cache: true,
                            type: "POST",
                            url:"${ctx}/admin/client/save.do",
                            data:$('#clientVersionForm').serialize(),// 你的formid
                            async: false,
                            error: function(request) {
                                alert("Connection error");
                            },
                            success: function(data) {
                                if(data.result == "success"){
                                    window.location="${ctx}/admin/client/list.html";
                                }else{
                                    alert(data.messages);
                                }
                            }
                        });
                    },
                    invalidHandler: function (form) {
                    }
                });
            })
        </script>

        <script type="text/javascript">

            function submitSoft(submitType){
                $("#submitType").val(submitType);
                $('#clientVersionForm').submit();
            }

            $('#id-input-apk,#id-input-icon,#id-input-gamecut,#id-input-ad,#id-input-screenshot').ace_file_input({
                no_file:'未选择文件 ...',
                btn_choose:'浏览',
                btn_change:'更改',
                droppable:false,
                onchange:null,
                thumbnail:false //| true | large
                //whitelist:'gif|png|jpg|jpeg'
                //blacklist:'exe|php'
                //onchange:''
                //
            });
        </script>
    </#assign>

    <@sublayout pageBreadCrumbs=pageBreadCrumbs pageCss=pageCss pageJavascript=pageJavascript currentMenu="ClientFlag-clintVersionListFlag">
    <form id="clientVersionForm" class="form-horizontal" action="${ctx}/admin/client/save.do" method="post">
        <!--上传APK块---->
        <div class="row">
            <div class="col-sm-12">
                <div class="widget-box">
                    <div class="widget-header">
                        <h4 class="widget-title">上传应用</h4>

                    </div>

                    <div class="widget-body">
                        <div class="widget-main">
                            <div class="form-group">
                                <label class="control-label col-xs-12 col-sm-1" >应用地址:</label>
                                <div class="col-xs-12 col-sm-6 control-label" style="text-align: left;">
                                    ${vo.downloadUrl!}

                                </div>
                                <div class="col-xs-12 col-sm-4 ">
                                    <a   class="btn btn-sm btn-success col-xs-4" href="${ctx}/admin/upload/download.do?path=${vo.downloadUrl!}">
                                        下载 <i class="ace-icon fa fa-arrow-right icon-on-right bigger-60"></i>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--上传ICON块---->
        <div class="row">
            <div class="col-sm-12">
                <div class="widget-box">
                    <div class="widget-header">
                        <h4 class="widget-title">上传图标(512x512.png)</h4>

                    </div>

                    <div class="widget-body">
                        <div class="widget-main">
                            <div>
                                <ul class="ace-thumbnails clearfix">

                                    <li><a id="icon512a" name="icon512a" data-rel="colorbox" href="${staticHost}${vo.icon512Url!}">
                                        <img id="icon512" name="icon512" width="256" height="256"   onerror="this.src='${ctx}/static/admin/assets/img/imgerror.png'"  src="${staticHost}${vo.icon512Url!}"/>
                                        </a>
                                    </li>
                                    <li><a id="icon125a" name="icon125a" data-rel="colorbox" href="${staticHost}${vo.icon125Url!}">
                                        <img id="icon125" name="icon125" width="62" height="62"   onerror="this.src='${ctx}/static/admin/assets/img/imgerror.png'" src="${staticHost}${vo.icon125Url!}"/>
                                    </a>
                                    </li>
                                    <li><a id="icon114a" name="icon114a" data-rel="colorbox" href="${staticHost}${vo.icon114Url!}">
                                        <img id="icon114" name="icon114" width="57" height="57"   onerror="this.src='${ctx}/static/admin/assets/img/imgerror.png'"  src="${staticHost}${vo.icon114Url!}"/>
                                    </a>
                                    </li>
                                    <li><a id="icon62a" name="icon62a" data-rel="colorbox" href="${staticHost}${vo.icon62Url!}">
                                        <img id="icon62" name="icon62" width="31" height="31"   onerror="this.src='${ctx}/static/admin/assets/img/imgerror.png'"  src="${staticHost}${vo.icon62Url!}"/>
                                    </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>



            <!---软件信息----->
            <div class="row">
                <div class="col-sm-12">
                    <div class="widget-box">
                        <div class="widget-header">
                            <h4 class="widget-title">客户端信息</h4>

                        </div>

                        <div class="widget-body">
                            <div class="widget-main">
                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="id">客户端编号:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" readonly="" name="id" id="id" class="form-control col-sm-4 required" value="${vo.id!}"/>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="clientName">客户端名称:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="clientName" id="clientName" class="form-control col-sm-4 required" value="${vo.clientName!}"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="packageName">软件包名:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" readonly="" name="packageName" id="packageName" class="form-control col-sm-4 required" value="${vo.packageName!}"/>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="firmware">固件版本:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <div>
                                                <select class="form-control"  name="firmware" id="firmware" <#if readonly?? >readonly=""</#if>   data-placeholder="Choose a State...">
                                                    <#list firewares as fireware>
                                                        <option value="${fireware.firewareSDK}" >
                                                            ${(fireware.firewareName)!}
                                                        </option>
                                                    </#list>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="minsdk">最小平台固件:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="minsdkName" id="minsdkName" class="form-control col-sm-4 " readonly="" value="${vo.minsdkName!}"/>
                                            <input type="hidden" name="minsdk" id="minsdk" class="form-control col-sm-4 " readonly="" value="${vo.minsdk!}"/>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="maxsdk">最大平台固件:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="maxsdkName" id="maxsdkName" class="form-control col-sm-4 " readonly="" value="${vo.maxsdkName!}"/>
                                            <input type="hidden" name="maxsdk" id="maxsdk" class="form-control col-sm-4 " readonly="" value="${vo.maxsdk!}"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="versionCode">版本号:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text"  name="versionCode" id="versionCode" class="form-control col-sm-4 required"  <#if readonly?? >readonly=""</#if>  value="${vo.versionCode!}"/>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="versionName">版本名称:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text"  name="versionName" id="versionName" class="form-control col-sm-4 required" <#if readonly?? >readonly=""</#if>  value="${vo.versionName!}"/>
                                        </div>
                                    </div>

                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="resolution">分辨率尺寸值:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <div>
                                                <input type="text" readonly="readonly"  name="resolutionShow" id="resolutionShow" class="form-control col-sm-4" value="${vo.resolutionShow!}"/>
                                                <input type="hidden"  name="resolution" id="resolution" class="form-control col-sm-4" value="${vo.resolution!}"/>
                                            </div>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2  no-padding-right" for="clientType">客户端类型:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <div>
                                                <select class="form-control"  name="clientType" id="clientType" <#if readonly?? >readonly=""</#if>  data-placeholder="Choose a State...">
                                                    <option value="0">通用</option>
                                                    <option value="1">定制</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">

                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="downloadNumber">版本下载量:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="downloadNumber" id="downloadNumber" <#if readonly?? >readonly=""</#if>  class="form-control col-sm-4" value="${vo.minsdk!}"/>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="language">总下载量:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="totalNumber" id="totalNumber" <#if readonly?? >readonly=""</#if>  class="form-control col-sm-4" value="${vo.minsdk!}"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="phoneModel">厂商的特定机型:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="phoneModel" id="phoneModel" <#if readonly?? >readonly=""</#if>  class="form-control col-sm-4 " value="${vo.phoneModel!}"/>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="language">语言:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <div>
                                                <select class="form-control"  name="language" id="language"  <#if readonly?? >readonly=""</#if> data-placeholder="Choose a State...">
                                                    <#list languages as lang>
                                                        <option value="${lang.itemValue}" >
                                                            ${(lang.itemTitle)!}
                                                        </option>
                                                    </#list>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2  no-padding-right" for="channelId">渠道商:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <div>
                                                <select class="form-control"  name="channelId" id="channelId"  <#if readonly?? >readonly=""</#if> data-placeholder="Choose a State...">
                                                    <option value="-1">请选择渠道商</option>
                                                    <#list channels as channel>
                                                        <option value="${channel.id}" >
                                                            ${(channel.channelName)!}
                                                        </option>
                                                    </#list>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="filesize">软件大小:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" readonly="" name="filesize" id="filesize"  <#if readonly?? >readonly=""</#if> class="form-control col-sm-4 " value="${vo.filesize!}"/>
                                            <input id="downloadUrl" name="downloadUrl" type="hidden" value="${vo.downloadUrl!}"/>
                                            <input id="checknum" name="checknum" type="hidden" value="${vo.checknum!}"/>
                                        </div>
                                    </div>

                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2" for="isLastVersion">是否最新版本:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <div>
                                                <select class="form-control" name="isLastVersion" id="isLastVersion"  <#if readonly?? >readonly=""</#if> data-placeholder="Choose a State...">
                                                    <option value="1">是</option>
                                                    <option value="0">否</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div>
                                        <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="updateLog">版本更新介绍:</label>
                                        <div class="control-label col-xs-10 col-sm-10 " >
                                            <textarea class=" col-sm-10 limited" id="updateLog" name="updateLog"  <#if readonly?? >readonly=""</#if> maxlength="1000">${vo.updateLog!}</textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <input id="iconUrl" name="iconUrl" type="hidden" value="${vo.iconUrl!}"/>
            <input id="createAdminId" name="createAdminId" type="hidden" value="${vo.createAdminId!}"/>
            <input type="hidden" name="submitType" id="submitType" value="${vo.submitType!}">
            <#if !readonly??  >
                <div class="clearfix form-actions">
                    <div class="col-md-offset-5 col-md-9">
                        <#if vo.state!=1>
                            <button class="btn btn-info" type="button" onclick="submitSoft(0)">
                                <i class="ace-icon fa fa-check bigger-110"></i> 保存
                            </button>
                        </#if>
                        &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;
                        <button class="btn btn-info" type="button" onclick="submitSoft(1)">
                            <i class="ace-icon fa fa-check bigger-110"></i> 直接发布
                        </button>
                    </div>
                </div>
            </#if>
        </form>
    </@sublayout>

    <div id="editModal" class="modal fade">
        <div class="modal-dialog" style="width: 1200px;">
            <div class="modal-content">
            </div>
        </div>
    </div>

<script src="${ctx}/static/admin/assets/js/jquery.validate.js"></script>
<script src="${ctx}/static/admin/assets/js/jquery.validate.messages_zh.js"></script>